package jmine.tec.web.wicket.component.command.button;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;

/**
 * @author icaro
 */
public class SaveAjaxCommand extends AbstractAjaxButtonCommand {

    private final SaveAjaxCommandHandler handler;

    private final String label;

    /**
     * Construtor
     * 
     * @param handler {@link SaveCommandHandler}
     * @param label label do botão
     */
    public SaveAjaxCommand(SaveAjaxCommandHandler handler, String label) {
        this.handler = handler;
        this.label = label;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getLabel() {
        return this.label;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void execute(AjaxRequestTarget target, Form<?> form) {
        this.handler.save(target);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onError(AjaxRequestTarget target, Form<?> form) {
        this.handler.onSubmitError(target);
    }
}
